#include "QGLView.h"

QGLView::QGLView(): QWidget(){

    visu = new QDessinGL(fichier,this);
    menuBar = new QMenuBar(this);
	progressBar = new QProgressBar(this);

    menuBar->setFixedHeight(30);

	progressBar->setFixedHeight(20);
	progressBar->setValue(0);

    mainLayout = new QVBoxLayout;
    QHBoxLayout* sLayout = new QHBoxLayout;

    sLayout->addWidget(visu);
    mainLayout->addWidget(menuBar);
    mainLayout->addLayout(sLayout);
	mainLayout->addWidget(progressBar);
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
    setLayout(mainLayout);
    createActions();
    createMenus();
    setWindowTitle(tr("Free the parrot"));
    visu->setFichier("parrot.ppm");
	connect(visu,SIGNAL(nbItPr(int)),this->progressBar,SLOT(setValue(int)));

}
QGLView::~QGLView(){}

void QGLView::open(){
    fichier = QFileDialog::getOpenFileName(this,"Choisissez une image PPM a ouvrir","./","Image PPM (*.ppm)");
    visu->setFichier(fichier);
}

void QGLView::openMask(){
	masque = QFileDialog::getOpenFileName(this,"Choisissez une image PPM a ouvrir","./","Image PPM (*.ppm)");
	visu->setMasque(masque);
}

void QGLView::closeEvent(QCloseEvent *event){
	//tools->close();
	event->accept();

}
void QGLView::createActions(){

	openAct = new QAction(tr("&Open..."), this);
	openAct->setShortcut(tr("Ctrl+O"));
	openAct->setStatusTip(tr("Open an existing file"));
	connect(openAct, SIGNAL(triggered()), this, SLOT(open()));

	openMaskAct = new QAction(tr("&Load mask from file..."), this);
	openMaskAct->setShortcut(tr("Ctrl+M"));
	openMaskAct->setStatusTip(tr("Open a mask to load"));
	connect(openMaskAct, SIGNAL(triggered()), this, SLOT(openMask()));

	exitAct = new QAction(tr("E&xit"), this);
	exitAct->setShortcut(tr("Ctrl+Q"));
	exitAct->setStatusTip(tr("Exit the application"));
	connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

}

void QGLView::createMenus(){
	fileMenu = menuBar->addMenu(tr("&File"));
	fileMenu->addAction(openAct);
	fileMenu->addAction(openMaskAct);
	fileMenu->addSeparator();
	fileMenu->addAction(exitAct);
}

void QGLView::setTools(QTools* _tools){
    tools = _tools;
}

